class LayoutController {
    def authenticateService 
    def index = {
 
        def categorys = org.grails.plugins.lookups.Lookup.codeList('personalCategory')
        def categoryInstanceList = []
        categorys.each{ category ->
             categoryInstanceList.add(Article.withCriteria {
                and{
                    eq('category', category.code)
                    or{
                        eq('editor', User.get(authenticateService.userDomain()?.id) )
                        receiver {
                            eq('id', authenticateService.userDomain()?.id)
                        }
                        eq('broadcast', true)
                    }
                }
                maxResults(5) 
                order("lastTime", "desc")
            })
        }

        def perfectTime 
 
        int hour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY)
        if (hour >= 6 && hour < 8) {
            perfectTime = "早上好" 
        } else if (hour >= 8 && hour < 11) {
            perfectTime = "上午好" 
        } else if (hour >= 11 && hour < 13) {
            perfectTime = "中午好" 
        } else if (hour >= 13 && hour < 18) {
            perfectTime = "下午好" 
        } else {
            perfectTime = "晚上好" 
        }

        ['categoryInstanceList': categoryInstanceList.findAll { it != null && !it.isEmpty() } ,
            perfectTime: perfectTime ]
    }

    def top = {
        ['id':authenticateService.userDomain()?.id]
     }
    def menu = {
 
    }
    def welcome = { }

}
